package com.schoolMall.controller.area;

import com.schoolMall.domain.Area;
import com.schoolMall.service.AreaService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author:zyh
 * @Time:2021-08-26-23:24
 * @email:1269231889@qq.com
 */
@Controller
@RequestMapping("/schoolMall/area")
public class AreaController {

    private Logger logger = LoggerFactory.getLogger(AreaController.class);

    @Autowired
    private AreaService areaService;

    @ResponseBody
    @RequestMapping(value = "/getAreaList", method = RequestMethod.GET)
    public Map<String, Object> getAreaList() {
        logger.info("AreaController#getAreaList start");
        HashMap<String, Object> modelMap = new HashMap<>();
        long start = System.currentTimeMillis();
        try {
            List<Area> areaList = areaService.getAreaList();
            logger.info("areaService#getAreaList:{}",areaList);
            modelMap.put("rows", areaList);
            modelMap.put("total", areaList.size());
        } catch (Exception e) {
            modelMap.put("success", false);
            modelMap.put("errMsg", e.toString());
        }
        long end = System.currentTimeMillis();
        logger.error("test error");
        logger.debug("project run0 time:{}",end-start);
        return modelMap;
    }
}
